<style>
    .leftTwo{
        float:left;
        width:50%;
        margin: 0;
        padding:5px 0px;
}

	tr.sub_row{background:#CCC;}
	tr.sub_row td{padding-left:20px;}
</style>
<div style="padding-bottom:20px;" class="button_section">
	<!--<form>
    	<input type="text"><input type="submit" value="search">
    </form>-->
       <div class="left width65p componentheading"><?php echo $page_title;?></div>
          <a class="button" href="<?php echo site_url('borrower/add')?>">Add New Borrowers</a>
        <div class="clear"></div>
</div>
<div class="box-header">Borrower List</div>
<table width="100%">
    <thead>
      <tr>
            <th width="30%" height="32">Name</th><!-- name(member_id), email ,address, contact no -->
            <th width="60%">Book details</th>
            <th width="10%">Action</th>
      </tr>
   </thead>
   <tbody>
      <?php if(count($borrowers) > 0): ?>
      <?php
      foreach($borrowers as $borrower) :
          $publication_details = $this->borrower_model->get_publication_list($borrower->id);
      ?>
            <tr>
            	<td>
                    <div><?php echo $borrower->first_name." ".$borrower->last_name;?><?php echo ($borrower->member_id ==0)?"(Non-member)":"(".$borrower->member_id.")";?></div>
                    <div>(<a href="mailto:<?php echo $borrower->email;?>"><?php echo $borrower->email;?></a>)</div>
                    <div>
                        <?php echo "".$borrower->address1.", ";?>
                        <?php echo "".$borrower->address2;?>
                    </div>
                    <div>
                        <?php echo "Phone/Mobile: ".$borrower->phone1." / ";?>
                        <?php echo "".$borrower->phone2;?>
                    </div>
                </td>
                <td>
                        <?php foreach($publication_details as $publication){
                            $refundable_qty = $publication->refundable_qty;
                            $non_refundable_qty = $publication->non_refundable_qty;
                            $today = strtotime(date('Y-m-d'));
                            $endDate = strtotime($publication->return_date);
                            $daysDiff = round(abs($endDate-$today)/60/60/24);
                            //$daysDiff = $publication->date_diff;
                            if($refundable_qty!=0 || $non_refundable_qty!=0){
                            ?>
                        <div class="leftTwo">
                            <div><strong><?php echo $publication->title." (".$publication->coding.")";?></strong></div>
                            <div><?php echo "Type:".$publication->type.", Publisher:".$publication->publisher;?></div>
                            <div><?php echo $publication->issue_date." -".$publication->return_date."(<strong>$daysDiff days</strong>)";?></div>
                            <div><?php echo "Refundable:".$refundable_qty.", Non-Refundable:".$non_refundable_qty;?></div>
                        </div>
                        <?php  }}?>
                </td>

               <td></td>
            </tr>
            
      <?php endforeach; ?>
      <?php else: ?>
      	<tr>
        	<td colspan="3">
      		<div class="error_message">
            	No borrower have been added.
            </div>
            </td>
        </tr>
      <?php endif; ?>
    </tbody>  
</table>
<div id="pagination">
	<?php echo $this->pagination->create_links(); ?>
</div>
<script>
	function delete_borrower(cid)
	{ 
		if(confirm('Are You Sure???'))	
		{
			$.post( '<?php echo site_url('borrower/delete');?>', {borrower_id : cid}, function(data){ window.location = '<?php echo current_url();?>';});
		}
	}
</script>